package leetcode;

import java.util.ArrayList;

/**
 * @Author Gan
 * @Date 2021/5/17 15:39
 * @Description:
 */
public class Solution1 {
    public static void main(String[] args) {
        System.out.println(countDigitOne(0));
    }
    public static int countDigitOne(int n) {
        int ans = 0;
        String str;
        //ArrayList<Integer> list = new ArrayList<>();
        for(int i = 0;i <= n;i++){
            str = String.valueOf(i);
            for(char ch:str.toCharArray()){
                if(ch == '1'){
                    ans++;
                }
            }
        }
        return ans;
    }
}
